/// Author: Samle
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';

/// 页面参数使用状态管理进行缓存
class PageStore {

  /// Books 页面查询参数管理
  setBooksParamsForm(Map paramsForm) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString('books_params', json.encode(paramsForm));
  }
  getBooksParamsForm() async {
    final prefs = await SharedPreferences.getInstance();
    final paramsForm = json.decode(prefs.getString('books_params') ?? '{}');
    return paramsForm;
  }
  /// Books 页面表单数据管理
  setBooksDataForm(Map dataForm) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString('books_form', json.encode(dataForm));
  }
  getBooksDataForm() async {
    final prefs = await SharedPreferences.getInstance();
    final dataForm = json.decode(prefs.getString('books_form') ?? '{}');
    return dataForm;
  }


  /// Words 页面查询参数管理
  setWordsParamsForm(Map paramsForm) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString('words_params', json.encode(paramsForm));
  }
  getWordsParamsForm() async {
    final prefs = await SharedPreferences.getInstance();
    final paramsForm = json.decode(prefs.getString('words_params') ?? '{}');
    return paramsForm;
  }
  /// Words 页面表单数据管理
  setWordsDataForm(Map dataForm) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString('words_form', json.encode(dataForm));
  }
  getWordsDataForm() async {
    final prefs = await SharedPreferences.getInstance();
    final dataForm = json.decode(prefs.getString('words_form') ?? '{}');
    return dataForm;
  }

}
